import { Item } from 'ant-design-vue/lib/menu';
import Mock from 'mockjs'
import { param2Obj } from '../../utils/decompose'
interface MockList {
    id: string,
    key: string;
    name: number,
    block: number,
    type: string,
    Vipname: string,
    grade: any,
    number: number,
    consume: string,
    balance: string,
    save: string,
    score: string,
    begin: string,
    over: string,
    isVip: boolean
}
let List: MockList[] = []
for (let i = 0; i < 400; i++) {
    let id = Mock.mock('@id')
    // let vip = Mock.mock('@integer(0, 3)')
    // List[i]["grade"] = vip ? "vip" + vip : ""

    List.push({
        id: id,
        key: id,
        name: Mock.mock('@id()'),
        block: Mock.mock(/\d{5,10}/),
        type: Mock.mock('@integer(0, 2)'),
        Vipname: Mock.mock('@cname'),
        // grade: 'Vip' + Mock.mock('@integer(0, 10)'),
        grade: Mock.mock('@integer(0, 3)') ? "vip" + Mock.mock('@integer(1, 3)') : "不是会员",
        number: Mock.mock(/^1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/),
        consume: Mock.mock('@integer(1000, 20000)'),
        balance: Mock.mock('@integer(1000, 200200)'),
        save: Mock.mock('@integer(1000, 220000)'),
        score: Mock.mock('@integer(1000, 2000)'),
        begin: Mock.mock('@datetime("yyyy-MM-dd A HH:mm:ss")'),
        over: Mock.mock('@datetime("yyyy-MM-dd A HH:mm:ss")'),
        isVip: false
    })
}
List.forEach(item => {
    if (item.grade.indexOf("vip") == -1) {
        item.type = "赶紧冲会员"
        item.isVip = false
    } else if (item.grade.indexOf("1") !== -1) {
        item.type = "普通会员"
        item.isVip = true
    } else if (item.grade.indexOf("2") !== -1) {
        item.type = "高级会员"
        item.isVip = true
    } else if (item.grade.indexOf("3") !== -1) {
        item.type = "超级会员"
        item.isVip = true
    }
})
export default {
    MockList: (config: any) => {
        let { Vipname, page, pagesize } = param2Obj(config.url)
        const newList = List.filter(item => {
            return item.Vipname.indexOf(Vipname) != -1
        })
        const newList2 = newList.filter((item, index) => {
            return (page - 1) * pagesize <= index && index < page * pagesize
        })
        return {
            code: 200,
            msg: "数据成功了",
            data: newList2,
            total: List.length
        }
    },
    MockListDel: (config: any) => {
        const { id } = JSON.parse(config.body)
        const index = List.findIndex(Item => {
            return Item.id !== id
        })
        List.splice(index, 1)
        return {
            code: 200,
            msg: "成功删除了",
            data: null,
        }
    },
    // MockListAdd: (config: any) => {
    //     const { name, block, type, grade, Vipname, number, consume, balance, save, score, begin, over, } = JSON.parse(config.body)
    //     let id = Mock.mock('@guid')
    //     List.unshift({
    //         id: id,
    //         key: id,
    //         name: name,
    //         block: block,
    //         type: type,
    //         grade: grade,
    //         Vipname: Vipname,
    //         number: number,
    //         consume: consume,
    //         balance: balance,
    //         save: save,
    //         score: score,
    //         begin: begin,
    //         over: over,
    //         isVip:boolean
    //     })
    //     return {
    //         code: 200,
    //         msg: "添加成功",
    //         data: null,
    //     }
    // }
}